package com.ruoyi.prize.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.prize.domain.Prize;
import com.ruoyi.prize.service.IPrizeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 兑换商品管理Controller
 * 
 * @author 秦永昆
 * @date 2023-02-12
 */
@RestController
@RequestMapping("/prize/prize")
public class PrizeController extends BaseController
{
    @Autowired
    private IPrizeService prizeService;

    /**
     * 查询兑换商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('prize:prize:list')")
    @GetMapping("/list")
    public TableDataInfo list(Prize prize)
    {
        startPage();
        List<Prize> list = prizeService.selectPrizeList(prize);
        return getDataTable(list);
    }
    /**
     * 查询兑换商品管理列表
     */
    //@PreAuthorize("@ss.hasPermi('prize:prize:list')")
    @GetMapping("/Homelist")
    public TableDataInfo Homelist(Prize prize)
    {
        startPage();
        List<Prize> list = prizeService.Homelist(prize);
        return getDataTable(list);
    }

    /**
     * 导出兑换商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('prize:prize:export')")
    @Log(title = "兑换商品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Prize prize)
    {
        List<Prize> list = prizeService.selectPrizeList(prize);
        ExcelUtil<Prize> util = new ExcelUtil<Prize>(Prize.class);
        util.exportExcel(response, list, "兑换商品管理数据");
    }

    /**
     * 获取兑换商品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('prize:prize:query')")
    @GetMapping(value = "/{prizeId}")
    public AjaxResult getInfo(@PathVariable("prizeId") Long prizeId)
    {
        return success(prizeService.selectPrizeByPrizeId(prizeId));
    }

    /**
     * 新增兑换商品管理
     */
    @PreAuthorize("@ss.hasPermi('prize:prize:add')")
    @Log(title = "兑换商品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Prize prize)
    {
        return toAjax(prizeService.insertPrize(prize));
    }

    /**
     * 修改兑换商品管理
     */
    @PreAuthorize("@ss.hasPermi('prize:prize:edit')")
    @Log(title = "兑换商品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Prize prize)
    {
        return toAjax(prizeService.updatePrize(prize));
    }

    /**
     * 删除兑换商品管理
     */
    @PreAuthorize("@ss.hasPermi('prize:prize:remove')")
    @Log(title = "兑换商品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{prizeIds}")
    public AjaxResult remove(@PathVariable Long[] prizeIds)
    {
        return toAjax(prizeService.deletePrizeByPrizeIds(prizeIds));
    }
}
